package tutor;

import static org.lwjgl.opengl.GL11.*;

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;

public class Tutorial1 extends Game {
	
	int x = 150;
	int y = 150;

	public void init() {
		Display.setTitle("Test title");

		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();

		glMatrixMode(GL_MODELVIEW);
		glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);
		glViewport(0, 0, Display.getWidth(), Display.getHeight());
	}

	public void update(long elapsedTime) {
	    if (Keyboard.isKeyDown(Keyboard.KEY_LEFT))
	        x -= 4;

	    if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
	        x += 4;

	    if (Keyboard.isKeyDown(Keyboard.KEY_UP))
	        y -= 4;

	    if (Keyboard.isKeyDown(Keyboard.KEY_DOWN))
	        y += 4;

	    if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
	        end();
	}

	public void render() {
	    glClear(GL_COLOR_BUFFER_BIT);
	    glColor3f(1, 1, 1);
	    glPushMatrix();
	    {
	    	glTranslatef(x, y, 0);
	    	glBegin(GL_QUADS);
	        {
	        	glVertex2f(0, 0);
	        	glVertex2f(0, 100);
	        	glVertex2f(100, 100);
	        	glVertex2f(100, 0);
	        }
	        glEnd(); // End the drawing.
	    }
	    glPopMatrix(); // Restore original settings.
	}

	public void resized() {
		glViewport(0, 0, Display.getWidth(), Display.getHeight());
	}

	public static void main(String[] args) {
		new Tutorial1();
	}
}
